package com.blyat.xsoft.auth.restful.service.impl;

import com.blyat.xsoft.auth.restful.entity.User;
import com.blyat.xsoft.auth.restful.mapper.UserMapper;
import com.blyat.xsoft.kernel.restful.service.CrudService;
import com.blyat.xsoft.auth.restful.service.RoleService;
import com.blyat.xsoft.auth.restful.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Objects;

/**
 * @author syh
 * @date 2019/10/21
 **/
@Service
public class UserServiceImpl extends CrudService<User, UserMapper> implements UserService {

    @Autowired
    private RoleService roleService;

    @Override
    public User getByUsername(String username) {
        User user = mapper.getByUsername(username);
        if (!Objects.isNull(user)) {
            user.setRoles(roleService.getByUserId(user.getId()));
        }
        return user;
    }
}
